﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Jzy.Core.Utility;
using Jzy.Core.Common.Basic;
using ECommerce.Common;
using ECommerce.BLL.Member;
using ECommerce.Model.Member;


public class SitePage : System.Web.UI.Page
{
    protected string WebAppPath
    {
        get
        {
            return GlobalVar.WebAppPath;
        }
    }
    public void CheckLogin()
    {
        if (IsTimeout())
        {
            string url = GlobalVar.WebAppPath + "site/login.aspx?FromUrl=" + Request.CurrentExecutionFilePath;
            Response.Redirect(url,true);            
        }
    }

    protected string Encript(object src)
    {
        return StrUtil.EncryptUrl(src);
    }

    protected string Decript(object src)
    {
        return StrUtil.DecryptUrl(src);
    }

    public static bool IsTimeout()
    {
        bool isTimeout = false;
        if (SiteSession.MemberLoginName == null)
        {
            MemberBaseBO member = new MemberBaseBO();
            if (SiteCookie.MemberLoginName != null)
            {
                LoginResult result = member.CheckLogin(SiteCookie.MemberLoginName, StrUtil.DecryptDES(SiteCookie.Password, SiteCookie.MemberLoginName));
                if (result == LoginResult.Success)
                {
                    member.SetSession(SiteCookie.MemberLoginName);
                }
                else
                {
                    isTimeout = true;
                }
            }
            else
            {
                isTimeout = true;
            }

        }
        return isTimeout;
    }
}
